#!/usr/bin/python

# Color Library ver 0.0.1


############################################################################
#    Copyright (C) 2007 by  Zolotarevsky Alexander (sh)                    #
#    zolotarevski@rambler.ru                                               #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################


esc_seq = "\x1b["

codes={}
codes["reset"]     = esc_seq + "39;49;00m"

codes["bold"]      = esc_seq + "01m"
codes["faint"]     = esc_seq + "02m"
codes["standout"]  = esc_seq + "03m"
codes["underline"] = esc_seq + "04m"
codes["blink"]     = esc_seq + "05m"
codes["overline"]  = esc_seq + "06m"

ansi_color_codes = []
for x in xrange(30, 38):
	ansi_color_codes.append("%im" % x)
	ansi_color_codes.append("%i;01m" % x)
#end

rgb_ansi_colors = [
	'0x000000', '0x555555', '0xAA0000', '0xFF5555',
	'0x00AA00',	'0x55FF55', '0xAA5500', '0xFFFF55',
	'0x0000AA', '0x5555FF', '0xAA00AA',	'0xFF55FF',
	'0x00AAAA', '0x55FFFF', '0xAAAAAA', '0xFFFFFF'
]

for x in xrange(len(rgb_ansi_colors)):
	codes[rgb_ansi_colors[x]] = esc_seq + ansi_color_codes[x]
#end

del x

codes["black"]				= codes["0x000000"]
codes["darkgray"]			= codes["0x555555"]

codes["red"]				= codes["0xFF5555"]
codes["darkred"]			= codes["0xAA0000"]

codes["green"]				= codes["0x55FF55"]
codes["darkgreen"]		= codes["0x00AA00"]

codes["yellow"]			= codes["0xFFFF55"]
codes["brown"]				= codes["0xAA5500"]

codes["blue"]				= codes["0x5555FF"]
codes["darkblue"]			= codes["0x0000AA"]

codes["fuchsia"]			= codes["0xFF55FF"]
codes["purple"]			= codes["0xAA00AA"]

codes["turquoise"]		= codes["0x55FFFF"]
codes["teal"]				= codes["0x00AAAA"]

codes["white"]				= codes["0xFFFFFF"]
codes["lightgray"]		= codes["0xAAAAAA"]

codes["darkteal"]			= codes["turquoise"]
codes["darkyellow"]		= codes["brown"]
codes["fuscia"]			= codes["fuchsia"]
codes["white"]				= codes["bold"]



def colorize(color_key, text):
	return codes[color_key] + text + codes["reset"]

def color(color_key):
	return codes[color_key]

def reset():
	return codes["reset"]

def black():
	return codes["black"]

def darkgray():
	return codes["darkgray"]

def red():
	return codes["red"]

def darkred():
	return codes["darkred"]

def green():
	return codes["green"]

def darkgreen():
	return codes["darkgreen"]

def yellow():
	return codes["yellow"]

def brown():
	return codes["brown"]

def blue():
	return codes["blue"]

def darkblue():
	return codes["darkblue"]

def fuchsia():
	return codes["fuchsia"]

def purple():
	return codes["purple"]

def turquoise():
	return codes["turquoise"]
	
def teal():
	return codes["teal"]

def white():
	return codes["white"]

def lightgray():
	return codes["lightgray"]
